<?php


namespace app\api\model;


use ApiOper;
use app\common\model\BaseModel;

class UserPhoneHistoryModel extends BaseModel
{
    protected $name = 'user_phone_history';

    function add($user_id, $old, $new) {
        $data = [
            'user_id' => $user_id,
            'old' => $old,
            'new' => $new,
        ];

        ApiOper::instance()->append_creater_info($data);

        self::create($data,true);
    }

    function get_list($user_id) {
        //$st = "select * from tb_user_phone_history where user_id = ? order by create_time desc";
        $beans = [
            'user_id' =>$user_id
        ];

        $rows = $this->where($beans)->order('create_time','desc')->select();


        $l = [];
        foreach ($rows as $row) {
            $l[] = [
                'old' => $row->getAttr('old'),
                'new' => $row->getAttr('new'),
                'create_time' => $row->getAttr('create_time'),
                'creator_name' => $row->getAttr('creator_name'),
            ];
        }
        return $l;
    }

}